Completed
Push — master ( 1f2ffc...cd17ec )
by Thomas
30s
created

Module.getManifest   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 15
rs 9.4285

1 Function

Rating   Name   Duplication   Size   Complexity  
B 0 12 6
1
'use strict'
2
3
const output = require('../output')
4
const path = require('path')
5
const jsonfile = require('jsonfile')
6
7
var Module = {}
8
9
/**
10
 * Get the manifest object for the module in the current directory.
11
 * @param {function(ModuleManifest)} callback
12
 * @param {string} basePath
13
 */
14
Module.getManifest = function (callback, basePath) {
15
  var modulePath = basePath ? path.join(basePath, 'module.json') : 'module.json'
16
  jsonfile.readFile(modulePath, function (err, module) {
17
    if (err) {
18
      output.err('Error reading module.json: ' + err)
19
      return
20
    }
21
    if (!('slug' in module) || !module.slug || typeof module.slug !== 'string' || !module.slug.length) {
22
      output.err('Please set a valid value for module.slug')
23
      return
24
    }
25
26
    callback(module)
27
  })
28
}
29
30
module.exports = Module
31